package org.example.spring.mapper;

import org.apache.ibatis.annotations.*;
import org.example.spring.entity.Books;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.awt.print.Book;
import java.io.Console;
import java.util.List;
@Mapper

public interface BookMapper {

    // 查询所有图书
    @Select("SELECT * FROM books")
    List<Books> getAllBooks();

    // 根据 ID 删除图书

    @Delete("DELETE FROM books WHERE book_id = #{book_id}")
    int deleteBooks(Integer book_id);

    @Insert("INSERT INTO books (book_name, author, address, book_type_name, description, status) " +
            "VALUES (#{bookName}, #{author}, #{address}, #{bookTypeName}, #{description}, #{status})")

    //    插入
    int insert(Books books);

    //    动态更新
    int update(Books books);

    //    分页查询
    @Select("SELECT * FROM `books` limit #{page},#{size}")
    List<Books> selectPage(int page, int size);

//    查询图书数量
    @Select("SELECT count(*) FROM books")
    Integer selectTotal();
}

